home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 September / Chip_2000-09_cd1.bin / sharewar / Slunec / app / 16 / ARCHIVES.SWG / 0017_ARJ Technical Reference.pas < prev    next >
Pascal/Delphi Source File  |  1997-05-11  |  10KB  |  242 lines

  1.  
  2.      ARJ TECHNICAL INFORMATION                                October 1995
  3.  
  4.  
  5.      ** IMPORTANT NEWS ****************************************************
  6.  
  7. Some  archiver support programs have designed ARJ archive identification
  8. schemes  that are not reliable. At ARJ  2.39, there are now two versions
  9. of  the  ARJSFX  self-extraction  module.  The  18K  byte  ARJSFX module
  10. supports  ARJ-SECURITY.  The  standard 16K  byte  ARJSFX module does NOT
  11. support  ARJ-SECURITY.  At  ARJ 2.50, there  is  a  new ARJSFXV multiple
  12. volume  self-extraction  module.  For the  first  time, the ARJ-SECURITY
  13. fields in the main ARJ header are publicly defined.
  14.  
  15. In  addition,  the main ARJ header  in  self-extracting archives MAY NOT
  16. immediately follow the EXE module now. z
  17.      ARJ has used the same ARJ archive identification scheme since ARJ
  18.      1.0.  The following is the algorithm:
  19.  
  20.      (1) find the ARJ header id bytes 0x60, 0xEA,
  21.      (2) read the next two bytes as the header record size in bytes,
  22.      (3) if the record size is greater than 2600, go back to the header
  23.      id file position, increment the file position, and go back to
  24.      step (1),
  25.      (4) read the header record based upon the previous byte count,
  26.      (5) calculate the 32 bit CRC of the header record data,
  27.      (6) read the next four bytes as the actual header record CRC,
  28.      (7) if the actual CRC does not equal the calculated CRC, go back
  29.      to the header id file position, increment the file position,
  30.      and go back to step (1).
  31.  
  32. It  is acceptable to start this identification algorithm at a point just
  33. after  the ARJ self-extraction EXE portion of an archive. This algorithm
  34. is  fully  demonstrated  in the UNARJ C  source  code. A portion of that
  35. source code is excerpted at the end of this document.
  36.  
  37. As  of  ARJ  2.10, the SFX  executable  modules are pre-compressed using
  38. LZEXE.  This  may  cause false  indications  with  EXE scanning programs
  39. showing  that  an ARJ SFX archive is  a  LZEXE compressed file. Only the
  40. executable  header module is LZEXE compressed. The actual archive is ARJ
  41. compressed,  of course. The LZEXE header is modified to avoid extraction
  42. by  UNLZEXE type programs. UNLZEXE may truncate an ARJ self-extractor of
  43. its archive.
  44.  
  45. All  SFX modules have an identification string located in the first 1000
  46. characters  of  the  executable. The  identification  string is "aRJsfX"
  47. without the quotes and in the exact case.
  48.  
  49. When  using listfiles with ARJ, ARJ support programs should use the "-p"
  50. option  to ensure that ARJ will only  extract the selected files from an
  51. ARJ archive. In addition, the listfiles should contain the full pathname
  52. information  as  stored  in  the ARJ  archive.  This  avoids the problem
  53. accessing files that have the same filename but different paths.
  54.  
  55. There  is  an  extended header bug in  older  versions  of ARJ, AV.C and
  56. UNARJ.C.  The extended header processing  in read_header() should skip 4
  57. bytes  for  the  extended header CRC and  not  2.  This is NOT a current
  58. problem as no versions of ARJ use the extended header.
  59.  
  60.      **********************************************************************
  61.  
  62.  
  63.      Modification history:
  64.      Date      Description of modification:
  65.      --------  ------------------------------------------------------------
  66.      07/07/95  Added information about SFX id string.
  67.      11/03/94  Improved SFX identification information.
  68.      01/21/94  Added find_header() routine.
  69.      03/17/93  Added information about ARJSFX change.
  70.      02/17/93  Added description of ARJ security fields.
  71.            Added archive date-modified field.
  72.      12/03/91  Added BACKUP flag to header arj flags.
  73.      11/21/91  Described the two types of headers separately.
  74.      11/11/91  Added information about the change in text mode processing.
  75.      06/28/91  Added several new HOST OS numbers.
  76.      05/19/91  Improved the description of extended header processing.
  77.      05/11/91  Simplified this document.  Added volume label type.
  78.      03/11/91  Added directory file type.
  79.      02/23/91  Added more comments.
  80.      01/10/91  Corrected timestamp description and header order of file mode.
  81.      10/30/90  Corrected values of flags in ARJ flags.
  82.  
  83.  
  84.      ARJ archives contains two types of header blocks:
  85.  
  86.     Archive main header - This is located at the head of the archive
  87.     Local file header   - This is located before each archived file
  88.  
  89.      Structure of main header (low order byte first):
  90.  
  91.      Bytes Description
  92.      ----- -------------------------------------------------------------------
  93.        2   header id (main and local file) = 0x60 0xEA
  94.        2   basic header size (from 'first_hdr_size' thru 'comment' below)
  95.          = first_hdr_size + strlen(filename) + 1 + strlen(comment) + 1
  96.          = 0 if end of archive
  97.          maximum header size is 2600
  98.  
  99.        1   first_hdr_size (size up to and including 'extra data')
  100.        1   archiver version number
  101.        1   minimum archiver version to extract
  102.        1   host OS   (0 = MSDOS, 1 = PRIMOS, 2 = UNIX, 3 = AMIGA, 4 = MAC-OS)
  103.              (5 = OS/2, 6 = APPLE GS, 7 = ATARI ST, 8 = NEXT)
  104.              (9 = VAX VMS)
  105.        1   arj flags
  106.              (0x01 = NOT USED)
  107.              (0x02 = OLD_SECURED_FLAG)
  108.              (0x04 = VOLUME_FLAG)  indicates presence of succeeding
  109.                        volume
  110.              (0x08 = NOT USED)
  111.              (0x10 = PATHSYM_FLAG) indicates archive name translated
  112.                        ("\" changed to "/")
  113.              (0x20 = BACKUP_FLAG) indicates backup type archive
  114.              (0x40 = SECURED_FLAG)
  115.        1   security version (2 = current)
  116.        1   file type        (must equal 2)
  117.        1   reserved
  118.        4   date time when original archive was created
  119.        4   date time when archive was last modified
  120.        4   archive size (currently used only for secured archives)
  121.        4   security envelope file position
  122.        2   filespec position in filename
  123.        2   length in bytes of security envelope data
  124.        2   (currently not used)
  125.        ?   (currently none)
  126.  
  127.        ?   filename of archive when created (null-terminated string)
  128.        ?   archive comment  (null-terminated string)
  129.  
  130.        4   basic header CRC
  131.  
  132.        2   1st extended header size (0 if none)
  133.        ?   1st extended header (currently not used)
  134.        4   1st extended header's CRC (not present when 0 extended header size)
  135.  
  136.  
  137.      Structure of local file header (low order byte first):
  138.  
  139.      Bytes Description
  140.      ----- -------------------------------------------------------------------
  141.        2   header id (main and local file) = 0x60 0xEA
  142.        2   basic header size (from 'first_hdr_size' thru 'comment' below)
  143.          = first_hdr_size + strlen(filename) + 1 + strlen(comment) + 1
  144.          = 0 if end of archive
  145.          maximum header size is 2600
  146.  
  147.        1   first_hdr_size (size up to and including 'extra data')
  148.        1   archiver version number
  149.        1   minimum archiver version to extract
  150.        1   host OS   (0 = MSDOS, 1 = PRIMOS, 2 = UNIX, 3 = AMIGA, 4 = MAC-OS)
  151.              (5 = OS/2, 6 = APPLE GS, 7 = ATARI ST, 8 = NEXT)
  152.              (9 = VAX VMS)
  153.        1   arj flags (0x01 = GARBLED_FLAG) indicates passworded file
  154.              (0x02 = NOT USED)
  155.              (0x04 = VOLUME_FLAG)  indicates continued file to next
  156.                        volume (file is split)
  157.              (0x08 = EXTFILE_FLAG) indicates file starting position
  158.                        field (for split files)
  159.              (0x10 = PATHSYM_FLAG) indicates filename translated
  160.                        ("\" changed to "/")
  161.              (0x20 = BACKUP_FLAG)  indicates file marked as backup
  162.        1   method    (0 = stored, 1 = compressed most ... 4 compressed fastest)
  163.        1   file type (0 = binary,    1 = 7-bit text)
  164.              (3 = directory, 4 = volume label)
  165.        1   reserved
  166.        4   date time modified
  167.        4   compressed size
  168.        4   original size (this will be different for text mode compression)
  169.        4   original file's CRC
  170.        2   filespec position in filename
  171.        2   file access mode
  172.        2   host data (currently not used)
  173.        ?   extra data
  174.        4 bytes for extended file starting position when used
  175.        (these bytes are present when EXTFILE_FLAG is set).
  176.        0 bytes otherwise.
  177.  
  178.        ?   filename (null-terminated string)
  179.        ?   comment  (null-terminated string)
  180.  
  181.        4   basic header CRC
  182.  
  183.        2   1st extended header size (0 if none)
  184.        ?   1st extended header (currently not used)
  185.        4   1st extended header's CRC (not present when 0 extended header size)
  186.  
  187.        ...
  188.  
  189.        ?   compressed file
  190.  
  191.  
  192.      Time stamp format:
  193.  
  194.     31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
  195.        |<---- year-1980 --->|<- month ->|<--- day ---->|
  196.  
  197.     15 14 13 12 11 10  9  8  7  6  5  4  3    2  1  0
  198.        |<--- hour --->|<---- minute --->|<- second/2 ->|
  199.  
  200.  
  201.      Routine to find an ARJ Header record:
  202.  
  203.        long find_header(FILE *fd)
  204.        {
  205.            long arcpos, lastpos;
  206.            int c;
  207.  
  208.            arcpos = file_tell(fd);
  209.            file_seek(fd, 0L, SEEK_END);
  210.            lastpos = file_tell(fd) - 2;
  211.            for ( ; arcpos < lastpos; arcpos++)
  212.            {
  213.                file_seek(fd, arcpos, SEEK_SET);
  214.                c = fget_byte(fd);
  215.                while (arcpos < lastpos)
  216.                {
  217.                    if (c != HEADER_ID_LO)  /* low order first */
  218.                        c = fget_byte(fd);
  219.                    else if ((c = fget_byte(fd)) == HEADER_ID_HI)
  220.                        break;
  221.                    arcpos++;
  222.                }
  223.                if (arcpos >= lastpos)
  224.                    break;
  225.                if ((headersize = fget_word(fd)) <= HEADERSIZE_MAX)
  226.                {
  227.                    crc = CRC_MASK;
  228.                    fread_crc(header, (int) headersize, fd);
  229.                    if ((crc ^ CRC_MASK) == fget_crc(fd))
  230.                    {
  231.                        file_seek(fd, arcpos, SEEK_SET);
  232.                        return arcpos;
  233.                    }
  234.                }
  235.            }
  236.            return -1;          /* could not find a valid header */
  237.        }
  238.  
  239.  
  240.      end of document
  241.  
  242.